package com.qijian.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qijian.system.domain.User;
import com.qijian.system.mapper.UserMapper;
import com.qijian.system.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public Map<String, Long> getUserIdMapByUserName(Collection<String> userName) {

        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.select("user_id", "user_name");
        wrapper.in("user_name", userName);
        wrapper.orderByAsc("status");
        return this.list(wrapper).stream().collect(Collectors.toMap(User::getUserName, User::getUserId, (a1, a2) -> a1));
    }

    @Override
    public Map<String, Long> getUserIdMapByNickName(Collection<String> nickName) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.select("user_id", "nick_name");
        wrapper.in("nick_name", nickName);
        wrapper.orderByAsc("status");
        return this.list(wrapper).stream().collect(Collectors.toMap(User::getNickName, User::getUserId, (a1, a2) -> a1));
    }
}
